using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public static class JsonLoader
{
    // 通用读取方法
    public static T LoadJson<T>(string fileName)
    {
        string filePath = Path.Combine(Application.streamingAssetsPath, fileName);

        if (!File.Exists(filePath))
        {
            Debug.LogError("JSON 文件不存在: " + filePath);
            return default;
        }

        try
        {
            string json = File.ReadAllText(filePath);
            T data = JsonUtility.FromJson<T>(json);
            return data;
        }
        catch (Exception e)
        {
            Debug.LogError("读取 JSON 出错: " + e.Message);
            return default;
        }
    }
}